<template>
  <div class="_inform">
    <el-drawer
      :visible.sync="drawer"
      :before-close="handleClose"
      :modal-append-to-body="false"
      :with-header="false"
      :modal="false"
      direction="rtl"
      size="7rem"
      style="margin-top: 1.01rem;"
    >
      <div style="padding: 15px;overflow-x: hidden;overflow-y: auto;height: 95%;">
        <div v-show="informArr.length==0" style="margin: 15% auto;text-align: center;">
          <img src="../assets/img/wsj.png" />
          <p style="color: #adafb5;">沒有新消息</p>
        </div>
        <div v-show="informArr.length>0">
          <transition-group
            enter-active-class="animated fadeInDown"
            leave-active-class="animated fadeOutRightBig"
            :duration="{ enter: 300, leave: 300 }"
          >
            <!--分别设置时间-->
            >
            <el-alert
              v-for="(item, index) in informArr"
              :key="item.id"
              :title="item.title"
              :type="item.type"
              :description="item.description"
              show-icon
              @close="informClose(index)"
            ></el-alert>
          </transition-group>
        </div>
      </div>
      <div class="_btn-div">
        <el-button type="text" icon="el-icon-delete" @click="informCloseAll">清除所有</el-button>
      </div>
    </el-drawer>
  </div>
</template>
<script>
export default {
  data() {
    return {
      drawer: false,
      informArr: [
        {
          id: "1",
          title: "成功提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "success"
        },
        {
          id: "2",
          title: "消息提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "info"
        },
        {
          id: "3",
          title: "警告提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "warning"
        },
        {
          id: "4",
          title: "错误提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "error"
        },
        {
          id: "5",
          title: "成功提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "success"
        },
        {
          id: "6",
          title: "消息提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "info"
        },
        {
          id: "7",
          title: "警告提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "warning"
        },
        {
          id: "8",
          title: "错误提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "error"
        },
        {
          id: "9",
          title: "成功提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "success"
        },
        {
          id: "10",
          title: "消息提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "info"
        },
        {
          id: "11",
          title: "警告提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "warning"
        },
        {
          id: "12",
          title: "错误提示的文案",
          description: "文字说明文字说明文字说明文字说明文字说明文字说明",
          type: "error"
        }
      ]
    };
  },
  computed: {
    config: function() {
      return this.$store.state.config;
    }
  },
  mounted() {
    let that = this;
    that.$store.state.config.informNum = this.informArr.length;
  },
  methods: {
    //点击信息块
    infoOnClick() {
      console.log("点击信息块");
    },
    //删除通知
    informClose(e) {
      let that = this;
      that.informArr.splice(e, 1);
      that.$store.state.config.informNum = this.informArr.length;
    },
    handleClose() {
      this.drawer = false;
    },
    informCloseAll() {
      let that = this;
      let index = that.informArr.length;
      for (var i = 0; i < index; i++) {
        (function(i) {
          setTimeout(function() {
            that.informArr.pop();
            that.$store.state.config.informNum = that.informArr.length;
          }, (i + 1) * 100);
        })(i);
      }
    }
  }
};
</script>
<style scoped>
.el-alert {
  margin: 15px 0px;
}
.el-alert:hover {
  transform: scale(1.02);
}
.el-alert:active {
  transform: scale(1.01);
}
._btn-div {
  text-align: center;
  width: 100%;
  position: absolute;
  bottom: 0px;
}
</style>
<style>
._inform .el-alert__closebtn {
  font-size: 16px;
}
</style>